home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / termResponse.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  3KB  |  172 lines

  1. /*
  2. **    termResponse.c
  3. **
  4. **    Signal event handling routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Terminal emulation debugging code. */
  13.  
  14. #ifdef DATAFEED
  15. BPTR DataFeed;
  16. #endif    /* DATAFEED */
  17.  
  18.     /* Yet another function pointer. */
  19.  
  20. typedef BYTE (* RESPONSE)(VOID);
  21.  
  22.     /* Signal response table entry. */
  23.  
  24. struct SignalResponseInfo
  25. {
  26.     RESPONSE    Routine;
  27.     ULONG        Mask;
  28.     BYTE        Loop;
  29. };
  30.  
  31.     /* Signal response table. */
  32.  
  33. STATIC struct SignalResponseInfo    ResponseTable[9];
  34. STATIC WORD                ResponseCount;
  35. STATIC ULONG                ResponseMask;
  36.  
  37.     /* AddResponse(RESPONSE Routine,ULONG Mask,BYTE Loop):
  38.      *
  39.      *    Register a signal response routine.
  40.      */
  41.  
  42. STATIC VOID __regargs
  43. AddResponse(RESPONSE Routine,ULONG Mask,BYTE Loop)
  44. {
  45.     ResponseTable[ResponseCount] . Routine    = Routine;
  46.     ResponseTable[ResponseCount] . Mask    = Mask;
  47.     ResponseTable[ResponseCount] . Loop    = Loop;
  48.  
  49.     ResponseMask |= Mask;
  50.  
  51.     ResponseCount++;
  52. }
  53.  
  54.     /* HandleResponse():
  55.      *
  56.      *    Register routines and corresponding signals,
  57.      *    wait for events and process them.
  58.      */
  59.  
  60. VOID
  61. HandleResponse()
  62. {
  63.     register ULONG    SignalSet;
  64.     register BYTE    Running;
  65.     register WORD    SingleShot,i;
  66.  
  67.     ResponseMask    = NULL;
  68.     ResponseCount    = 0;
  69.  
  70.     AddResponse((RESPONSE)HandleSerialCheck,SIG_CHECK,FALSE);
  71.  
  72.     if(WorkbenchPort)
  73.         AddResponse((RESPONSE)HandleWorkbenchWindow,SIG_WORKBENCH,FALSE);
  74.  
  75.     if(XEM_Signal)
  76.         AddResponse((RESPONSE)HandleExternalEmulation,XEM_Signal,FALSE);
  77.  
  78.     AddResponse((RESPONSE)HandleClipboard,SIG_CLIP,FALSE);
  79.  
  80.     SingleShot = ResponseCount;
  81.  
  82.     if(ReadPort && Status != STATUS_HOLDING)
  83.         AddResponse(HandleSerial,SIG_SERIAL,TRUE);
  84.  
  85.     AddResponse(HandleWindow,SIG_WINDOW,TRUE);
  86.  
  87. #ifdef USE_AREXX
  88.  
  89.     if(TermRexxPort)
  90.         AddResponse(HandleRexx,SIG_REXX,TRUE);
  91.  
  92. #endif    /* USE_AREXX */
  93.  
  94.     if(PacketWindow)
  95.         AddResponse(HandlePacket,SIG_PACKET,TRUE);
  96.  
  97.     if(ReviewPort)
  98.         AddResponse(HandleReview,SIG_REVIEW,TRUE);
  99.  
  100.         /* Wait for events. */
  101.  
  102. #ifdef DATAFEED
  103.     if(HostReadBuffer || DataHold || DataFeed)
  104. #else
  105.     if(HostReadBuffer || DataHold)
  106. #endif    /* DATAFEED */
  107.     {
  108.         if(ReadPort && Status != STATUS_HOLDING)
  109.             SignalSet = CheckSignal(ResponseMask) | SIG_SERIAL;
  110.         else
  111.             SignalSet = CheckSignal(ResponseMask);
  112.     }
  113.     else
  114.         SignalSet = Wait(ResponseMask);
  115.  
  116.         /* Handle single-shot events. */
  117.  
  118.     for(i = 0 ; i < SingleShot ; i++)
  119.     {
  120.         if(SignalSet & ResponseTable[i] . Mask)
  121.             (*ResponseTable[i] . Routine)();
  122.     }
  123.  
  124. #ifdef DATAFEED
  125.     ClearCursor();
  126. #endif    /* DATAFEED */
  127.  
  128.         /* Handle loop-fed events. */
  129.  
  130.     do
  131.     {
  132.         Running = FALSE;
  133.  
  134.         for(i = SingleShot ; !MainTerminated && i < ResponseCount ; i++)
  135.         {
  136.             if(SignalSet & ResponseTable[i] . Mask)
  137.             {
  138.                 if((*ResponseTable[i] . Routine)())
  139.                     Running = TRUE;
  140.                 else
  141.                     SignalSet &= ~ResponseTable[i] . Mask;
  142.             }
  143.         }
  144. #ifdef DATAFEED
  145.         if(DataFeed && Status != STATUS_HOLDING)
  146.         {
  147.             UBYTE    Buffer[256];
  148.             LONG    Len;
  149.  
  150.             if((Len = FRead(DataFeed,Buffer,1,256)) > 0)
  151.             {
  152.                 if(Marking)
  153.                     DropMarker();
  154.  
  155.                 ConProcess(Buffer,Len);
  156.             }
  157.             else
  158.             {
  159.                 Close(DataFeed);
  160.  
  161.                 DataFeed = NULL;
  162.             }
  163.         }
  164. #endif    /* DATAFEED */
  165.     }
  166.     while(Running && !MainTerminated);
  167.  
  168. #ifdef DATAFEED
  169.     DrawCursor();
  170. #endif    /* DATAFEED */
  171. }
  172.